#include "widget.h"
#include "ui_widget.h"
#include<QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->horizontalSlider->setValue(200);
    ui->horizontalSlider->setMaximum(1000);
    ui->horizontalSlider->setMinimum(100);
    ui->horizontalSlider->setSingleStep(50);
 QShortcut * cut1=new QShortcut(this);
 cut1->setKey(QKeySequence("-"));
 QShortcut * cut2=new QShortcut(this);
 cut2->setKey(QKeySequence("="));
 //使用信号与槽
 connect(cut1,&QShortcut::activated,this,&Widget::handleWightSub);
 connect(cut2,&QShortcut::activated,this,&Widget::handleWightAdd);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handleWightSub()
{
    //获取当前的窗口尺寸
    int val=ui->horizontalSlider->value();
   ui->horizontalSlider->setValue(val-50);
}

void Widget::handleWightAdd()
{
    int val=ui->horizontalSlider->value();
   ui->horizontalSlider->setValue(val+50);
}
//void Widget::on_horizontalSlider_valueChanged(int value)
//{
//    const QRect rect=this->geometry();
//  this->setGeometry(rect.x(),rect.y(),value,rect.height());
//}

